home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mastering Web Site Development
/
Microsoft Mastering Web Site Development (Microsoft) (1997).iso
/
Media
/
Ch08
/
W08D030.cc2
< prev
next >
Wrap
Text File
|
1997-04-24
|
3KB
|
54 lines
0, In this demonstration, you will see how to test a
4, component that you have built in Visual Basic 5.0.
8, The easiest way to test a component is to create
10, a project group that contains the component
13, project, and a test project. I've already opened the Math
17, project from a previous demonstration. Now, I'll
20, create a project group by adding a new project to
22, this one. I'll choose File, Add Project, and then
28, I'll select a Standard EXE, and click Open. Once I
33, do this, a project group is created. And if you
36, look in the Project Explorer window you'll see two
39, projects ù the Math component project that was
41, already there, and the new project that I just added,
44, which is called Project1. Project1 already comes
48, with a form. I'll put a button on the form that
52, when clicked will call the Math component to square a
55, value and print the result to the form. I'll
58, double-click the button to add code to it. The code for
63, the click event will create a variable called X of
66, type Math.Square. Then I'll call the Squareit
74, method, passing a value of 5, and print the result
78, to the form. Before this code will work properly,
88, you have to add a library reference to the
89, component that you're testing. In this case, I'll need to
92, add a library reference to the Math component. To
95, do that I'll select Project, References. When the
102, References dialog box comes up, I'll select the
106, Math component, and click OK. Next, you must set
112, Project1 as the start up project. You can do this by
116, right-clicking on the project and choosing Set as
119, Start Up. Now when I click the Play button, the
123, Test project will run instead of the Math project. I
126, want to trace the call to the Squareit function,
129, so I'll place a breakpoint on this line by choosing
132, Debug, Toggle Breakpoint. You'll notice that it
135, highlights the code in red to indicate that it's a
137, breakpoint. Now I'll run the project by clicking
140, Play, and when it comes up, I'll click the Command
145, button. When I click the button, execution stops at
149, the line of code where I set the breakpoint. I
152, can now begin stepping through the code to observe
153, what's happening. I'll choose Debug, Step Into, and
158, that will actually step into the Squareit
160, function as it's called. If I hold the mouse over
164, variables, I can see the values that are in them. You'll
166, notice that Squareit is currently zero. As I continue
169, stepping through the code, that value will
172, change. So now Squareit is 25. If I continue stepping,
178, I'll eventually return to the original function that
180, called it. I'll just click the Play button to
185, continue execution, and you'll notice that it prints
187, 25 to the form. By adding a test project, you can
191, quickly test and debug your ActiveX projects.
196, END